package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.MessageDAO;
import model.UserDAO;
import beans.MessageBean;
import beans.UserBean;

/**
 * Servlet implementation class ConversationServlet
 */
@WebServlet("/ConversationServlet")
public class ConversationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ConversationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {	    
			MessageBean message = new MessageBean();
			String ID = request.getParameter("id");
			String partner = request.getParameter("partner");
			message.setCommentID(Integer.parseInt(ID));
			//Debug
			System.out.println(message.getCommentID());
			LinkedList<MessageBean> conversationmessages = null;
			conversationmessages = MessageDAO.getConversation(message);
			//Set the session's attributes
			HttpSession session = request.getSession(true);
			session.setAttribute("partnername", partner);
			session.setAttribute("conversationmessages", conversationmessages);
			response.sendRedirect("conversation.jsp"); //logged-in page      		
		} 


		catch (Throwable theException) 	    
		{
			System.out.println(theException); 
		}	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
